//
//  ProgramModel.m
//  RainbowFM
//
//  Created by Kratos on 14/12/24.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "ProgramModel.h"

#import "ProgramAPI.h"

@implementation ProgramModel

+(instancetype)sharedModel
{
    static ProgramModel *programModel = nil;
    static dispatch_once_t once;
    
    dispatch_once(&once, ^{
        programModel = [[ProgramModel alloc] init];
    });
    
    return programModel;
}

-(void)fetchProgramListWithVip:(NSString *)vip
                   currentPage:(int)currentPage
                      pageSize:(int)pageSize
                        result:(void (^)(NSArray *list, NSString *msg))res
{
    ProgramAPI *api = [ProgramAPI new];
    [api fetchProgramListWithVip:vip currentPage:_F(@"%d",currentPage) pageSize:_F(@"%d",pageSize) result:^(NSArray *list, NSString *msg) {
        NSMutableArray *itemList = [NSMutableArray array];
        for (NSDictionary *dic in list) {
            ProgramItem *item = [[ProgramItem alloc]initWithDataDic:dic];
            [itemList addObject:item];
        }
        
        res(itemList,msg);
    }];
}

@end

@implementation ProgramItem

-(NSDictionary *)attributeMapDictionary
{
    return @{@"programId":@"ID",
             @"ACTNAME":@"ACTNAME",
             @"ACTDESC":@"ACTDESC",
             @"ACTDETILDESC":@"ACTDETILDESC",
             @"PICURL":@"PICURL",
             @"MEURL":@"MEURL",
             @"STARTTIME":@"STARTTIME",
             @"ENDTIME":@"ENDTIME",
             @"ZCRID":@"ZCRID"};
}

-(NSString *)PICURL
{
    if (_PICURL) {
        if (![_PICURL isKindOfClass:[NSNull class]]) {
            return _PICURL;
        }else{
            return nil;
        }
    }else{
        return nil;
    }
}

-(NSString *)MEURL
{
    if (_MEURL) {
        if (![_MEURL isKindOfClass:[NSNull class]]) {
            return _MEURL;
        }else{
            return nil;
        }
    }else{
        return nil;
    }
}

@end